// app.js
import utils from "./utils/utils";
import http from "./utils/http";
import verify from "./utils/verify";
App({
    token: "",
    refreshToken: "",
    onLaunch() {
        // 通过本地存储的 token 来判断用户的登录状态，在小程序启动时读取本地存储并记录到应用实例当中，方便其它页面全局访问
        this.getToken();
        this.getRefreshToken()
    },
    getToken() {
        wx.getStorage({
            key: "token",
            success: ({ data }) => {
                this.token = data;
            },
            fail() {},
        });
    },
    setToken(token) {
        // 拼凑完整 token
        token = "Bearer " + token;
        this.token = token;
        // 本地存储 token 和 refresh_token
        wx.setStorage({
            key: "token",
            data: this.token,
        });
    },
    getRefreshToken() {
        wx.getStorage({
            key: "refreshToken",
            success: ({ data }) => {
                this.refreshToken = data;
            },
            fail() {},
        });
    },
    setRefreshToken(refreshToken) {
        // 拼凑完整 refreshToken
        refreshToken = "Bearer " + refreshToken;
        this.refreshToken = refreshToken;
        wx.setStorage({
            key: "refreshToken",
            data: this.refreshToken,
        });
    },
});